//Первая лаба по jdbc

package dao;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConnectWithoutDriverManager {
    
    public static void main(String[] args) throws SQLException {
        
        Connection conn = null;
        
        try {
            Driver driver = new com.mysql.jdbc.Driver();
            
            String url = "jdbc:mysql://localhost/production_eshop";
            String user = "root";
            String password = "2479";
            
            String sql = "SELECT id, login, email FROM User";
            
            Properties prop = new Properties();
            prop.setProperty("user", user);
            prop.setProperty("password", password);
            
            conn = driver.connect(url, prop);
            
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            
            while (rs.next()){
                int id = rs.getInt("id");
                String login = rs.getString("login");
                String email = rs.getString("email");
                System.out.println("User[id=" + id + ", login='" + login + "', email='" + email + "']");
                
            }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
    }
}
